<template>
  <div>
    <div v-for="item in imgList" :key="item.id">
      <img :src="'http://127.0.0.1:3000' + item.img" width="100%" />
      <p style="fontsize: 20px; text-align: center">{{ item.goodsname }}</p>
      <p style="fontsize: 15px; text-align: center">
        市场价：{{ item.market_price }}
      </p>
      <p style="fontsize: 15px; text-align: center">{{ item.price }}</p>
      <button class="ipt7" @click="addcar(item.id)">加入购物车</button>
    </div>
  </div>
</template>

<script>
import { getgoodsinfo, cartAdd } from "../request";
export default {
  data() {
    return {
      imgList: [],
    };
  },
  created() {
    this.getData(this.$route.params.id);
  },
  methods: {
    async getData(id) {
      let res = await getgoodsinfo(id);
      this.imgList = res;
      console.log(res);
      console.log(this.imgList);
    },
    async addcar(id) {
      this.cateList = await cartAdd({
        uid: JSON.parse(localStorage.getItem("userInfo")).uid,
        goodsid: id,
        num: 1,
      });
      console.log(this.cateList);
    },
  },
};
</script>

<style>
.ipt7 {
  width: 80px;
  height: 40px;
  background: red;
  color: white;
  border: none;
  outline: none;
  font-size: 15px;
  margin-left: 40%;
}
</style>